<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="员工编号" prop="userid">
        <el-input
          v-model="queryParams.userid"
          placeholder="请输入员工编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="员工姓名" prop="username">
        <el-input
          v-model="queryParams.username"
          placeholder="请输入员工姓名"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:attendance:add']"
        >新增</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['system:attendance:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="attendanceList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="考勤编号" align="center" prop="aid" />
      <el-table-column label="员工编号" align="center" prop="userid" />
      <el-table-column label="员工姓名" align="center" prop="username" />
      <el-table-column label="员工部门" align="center" prop="department" />
      <el-table-column label="岗位" align="center" prop="deptdetailid" />
      <el-table-column label="电话" align="center" prop="phone" />


      <el-table-column label="考勤情况" align="center"  >
<!--        <el-button icon="el-icon-search" size="mini" @click="tiaozhuan">详情</el-button>-->


        <el-tooltip placement="top">
          <div slot="content">正常<br/>
          </div>

          <el-button>详 情</el-button>
        </el-tooltip>


      </el-table-column>

      <el-table-column label="考勤日期" align="center" prop="time" />




<!--      <el-table-column label="考勤日期" align="center"  prop="time">-->

<!--        <template>-->
<!--          <div class="block">-->
<!--&lt;!&ndash;            <span class="demonstration">默认</span>&ndash;&gt;-->


<!--            <el-date-picker-->
<!--              v-model="value1"-->
<!--              type="date"-->
<!--              placeholder="选择日期">-->
<!--            </el-date-picker>-->


<!--          </div>-->
<!--          &lt;!&ndash;            <div class="block">&ndash;&gt;-->
<!--          &lt;!&ndash;              <span class="demonstration">带快捷选项</span>&ndash;&gt;-->
<!--          &lt;!&ndash;              <el-date-picker&ndash;&gt;-->
<!--          &lt;!&ndash;                v-model="value2"&ndash;&gt;-->
<!--          &lt;!&ndash;                align="right"&ndash;&gt;-->
<!--          &lt;!&ndash;                type="date"&ndash;&gt;-->
<!--          &lt;!&ndash;                placeholder="选择日期"&ndash;&gt;-->
<!--          &lt;!&ndash;                :picker-options="pickerOptions">&ndash;&gt;-->
<!--          &lt;!&ndash;              </el-date-picker>&ndash;&gt;-->
<!--          &lt;!&ndash;            </div>&ndash;&gt;-->
<!--        </template>-->

<!--      </el-table-column>-->


      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:attendance:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['system:attendance:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改考勤信息管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="员工编号" prop="userid">
          <el-input v-model="form.userid" placeholder="请输入员工编号" />
        </el-form-item>
        <el-form-item label="员工姓名" prop="username">

          <el-select v-model="form.username" filterable placeholder="请选择">
            <el-option
              v-for="item in options"
              :key="item.username"
              :label="item.storeName"
              :value="item.username">
            </el-option>
          </el-select>

<!--          <el-input v-model="form.username" placeholder="请输入员工姓名" />-->

        </el-form-item>
        <el-form-item label="员工部门" prop="department">
          <el-input v-model="form.department" placeholder="请输入员工部门" />
        </el-form-item>
        <el-form-item label="岗位" prop="deptdetailid">
          <el-input v-model="form.deptdetailid" placeholder="请输入岗位" />
        </el-form-item>
        <el-form-item label="电话" prop="phone">
          <el-input v-model="form.phone" placeholder="请输入电话" />
        </el-form-item>
        <el-form-item label="考勤情况" prop="attendance">
          <el-input v-model="form.attendance" placeholder="请输入考勤情况" />
        </el-form-item>
        <el-form-item label="考勤时间" prop="time">
          <el-input v-model="form.time" placeholder="请输入考勤时间" />
<!--          <template>-->
<!--            <div class="block">-->
<!--              <span class="demonstration">默认</span>-->
<!--              <el-date-picker-->
<!--                v-model="value1"-->
<!--                type="date"-->
<!--                placeholder="选择日期">-->
<!--              </el-date-picker>-->
<!--            </div>-->
<!--            <div class="block">-->
<!--              <span class="demonstration">带快捷选项</span>-->
<!--              <el-date-picker-->
<!--                v-model="value2"-->
<!--                align="right"-->
<!--                type="date"-->
<!--                placeholder="选择日期"-->
<!--                :picker-options="pickerOptions">-->
<!--              </el-date-picker>-->
<!--            </div>-->
<!--          </template>-->
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>

import {listkqxx, listAttendance, getAttendance, delAttendance, addAttendance, updateAttendance } from "@/api/system/attendance";


export default {
  name: "Attendance",

  data() {
    return {


      //抽屉
      drawer: false,


      //日期选择器
      pickerOptions: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            picker.$emit('pick', new Date());
          }
        }, {
          text: '昨天',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24);
            picker.$emit('pick', date);
          }
        }, {
          text: '一周前',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', date);
          }
        }]
      },






      value1: '',
      value2: '',

      options: [], //存储所以的mingz信息
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 考勤信息管理表格数据
      attendanceList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userid: null,
        username: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        userid: [
          { required: true, message: "员工编号不能为空", trigger: "blur" }
        ],
        username: [
          { required: true, message: "员工姓名不能为空", trigger: "blur" }
        ],
        department: [
          { required: true, message: "员工部门不能为空", trigger: "blur" }
        ],
        time: [
          { required: true, message: "考勤信息更新时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {

    /** 跳转函数 */
    tiaozhuan() {
      this.$router.push({path: '/system/kaoqin'});
    },

    /** 查询考勤信息管理列表 */
    getList() {
      this.loading = true;
      listAttendance(this.queryParams).then(response => {
        this.attendanceList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        aid: null,
        userid: null,
        username: null,
        department: null,
        deptdetailid: null,
        phone: null,
        attendance: null,
        time: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.aid)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加考勤信息管理";

      //调用后端展示所有名字，下拉框展示

      listkqxx().then(aaa =>{
        console.log("结果： ",JSON.stringify(aaa))
        this.options = aaa.data
      })

    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const aid = row.aid || this.ids
      getAttendance(aid).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改考勤信息管理";
      });

      //调用后端展示所有名字，下拉框展示

      listkqxx().then(aaa =>{
        console.log("结果： ",JSON.stringify(aaa))
        this.options = aaa.data
      })

    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.aid != null) {
            updateAttendance(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addAttendance(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const aids = row.aid || this.ids;
      this.$modal.confirm('是否确认删除考勤信息管理编号为"' + aids + '"的数据项？').then(function() {
        return delAttendance(aids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/attendance/export', {
        ...this.queryParams
      }, `attendance_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
